package com.ptszyxx.popose.module.main.mine.adapter;

import static java.io.File.separator;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ptszyxx.popose.databinding.ItemMineLookBinding;
import com.ptszyxx.popose.module.main.mine.vm.MineLookTabVM;
import com.ysg.http.data.entity.mine.MineLookEntity;
import com.ysg.http.data.entity.user.UserResult;
import com.ysg.utils.YStringUtil;

public class MineLookAdapter extends BaseQuickAdapter<MineLookEntity, BaseDataBindingHolder<ItemMineLookBinding>> {

    private MineLookTabVM viewModel;
    private Presenter mPresenter = new Presenter();

    public MineLookAdapter(MineLookTabVM viewModel) {
        super(R.layout.item_mine_look);
        this.viewModel = viewModel;
    }

    @Override
    protected void convert(BaseDataBindingHolder<ItemMineLookBinding> holder, MineLookEntity item) {
        ItemMineLookBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.setEntity(item);
            binding.setViewModel(viewModel);
            binding.setPresenter(mPresenter);
            binding.setPosition(holder.getBindingAdapterPosition());
            binding.executePendingBindings();

            UserResult user = item.getUser();
            //个人信息：拼接
            if (user != null){
                StringBuffer sb = new StringBuffer();
                if (YStringUtil.isNotEmpty(user.getAddress())){
                    sb.append(user.getAddress() + separator);
                }
                if (YStringUtil.isNotEmpty(user.getAge() + "") && YStringUtil.noEq(0, user.getAge() + "")){
                    sb.append(user.getAge() + getContext().getResources().getString(R.string.year_old) + separator);
                }
                if (YStringUtil.isNotEmpty(user.getShengao())){
                    sb.append(user.getShengao() + separator);
                }
                if (YStringUtil.isNotEmpty(user.getZhiyename())){
                    sb.append(user.getZhiyename() + separator);
                }
                binding.tvInfo.setText(YStringUtil.clearEnd(sb.toString(), separator));
            }
        }
    }

    public static class Presenter{
        public void onChatClick(MineLookTabVM viewModel, MineLookEntity entity){
            UserResult user = entity.getUser();
            YActivityUtil.getInstance().jumpChat(viewModel, user.getTengxuncode()+"", user.getNick(), user.getPic());
        }
    }







}
